home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / win_subs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-25  |  11.1 KB  |  369 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: win_subs.c,v 1.3 89/09/25 09:14:47 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/win_subs.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/win_subs.c,v $$Revision: 1.3 $";
  12.  
  13. /* Teminal emulator functions called from put_window() */
  14.  
  15. #include "bitmap.h"
  16. #include "font.h"
  17. #include "defs.h"
  18. #include "window.h"
  19. #include "clip.h"
  20. #include <stdio.h>
  21.  
  22. #define FSIZE(c)    ((int) (W(font)->head.c))
  23. #define Abs(x)        ((x)>0?(x):-(x))
  24.  
  25. /*****************************************************************************
  26.  *    Do raster ops
  27.  */
  28.  
  29. int
  30. win_rop(win,window)
  31. register WINDOW *win;
  32. BITMAP *window;
  33.     {
  34.     register int *p = W(esc);
  35.     register int op;
  36.  
  37.     if (W(flags)&W_REVERSE)
  38.        op = ROP_INVERT(W(op));
  39.     else
  40.        op = W(op);
  41.  
  42. #ifdef DEBUG
  43.     dprintf(B)(stderr,"%s: blit\t",W(tty));
  44. #endif
  45.     switch (W(esc_cnt)) {
  46.        case 0:        /* set raster op function */
  47.                W(op) = W(op)&~NOCOLOR | NOCOLOR&GET_OP(*p);
  48.                if (W(flags)&W_OVER) {
  49.                   W(style) = GET_OP(*p);
  50.                   if ((W(flags)&W_REVERSE) ^ (W(flags)&W_STANDOUT))
  51.                      W(style) = ROP_INVERT(*p);
  52.                   }
  53. #ifdef DEBUG
  54.                dprintf(B)(stderr,"setting function %d\n",p[0]);
  55. #endif
  56.                break;
  57.        case 1:    /* set raster op color && function */
  58.                W(op) = (NOCOLOR&GET_OP(p[0])) | (GETCOLOR(p[1]));
  59. #ifdef DEBUG
  60.                dprintf(B)(stderr,"setting mode %d, color %d\n",p[0],p[1]);
  61. #endif
  62.                break;
  63.  
  64.        case 3:        /* ras_write */
  65.                bit_blit(window,Scalex(p[0]),Scaley(p[1]),
  66.                                Scalex(p[2]),Scaley(p[3]),
  67.                                op,NULL_DATA,0,0);
  68.                if (Do_clip())
  69.                   Set_clip(Scalex(p[0]),Scaley(p[1]),
  70.                            Scalex(p[0])+Scalex(p[2]),
  71.                            Scaley(p[1])+Scaley(p[3]));
  72.                break;
  73.        case 4:        /* ras_write  specify dest */
  74.                if (p[4]>MAXBITMAPS)
  75.                   break;
  76.                if (p[4]>0 && W(bitmaps)[p[4]-1]== (BITMAP *) 0)
  77.                   W(bitmaps)[p[4]-1] = bit_alloc(
  78.                               Scalex(p[0])+Scalex(p[2]),
  79.                               Scaley(p[1])+Scaley(p[3]),NULL_DATA,DEPTH);
  80.                bit_blit(p[4]?W(bitmaps)[p[4]-1]:window,
  81.                                Scalex(p[0]),Scaley(p[1]),
  82.                                Scalex(p[2]),Scaley(p[3]),
  83.                                op,0,0,0);
  84.                if (Do_clip() && p[4]==0)
  85.                   Set_clip(Scalex(p[0]),Scaley(p[1]),
  86.                            Scalex(p[0])+Scalex(p[2]),
  87.                            Scaley(p[1])+Scaley(p[3]));
  88.                break;
  89.        case 5:        /* ras_copy */
  90.                bit_blit(window,Scalex(p[0]),Scaley(p[1]),
  91.                                Scalex(p[2]),Scaley(p[3]),
  92.                                op,window,
  93.                                Scalex(p[4]),Scaley(p[5]));
  94.                if (Do_clip())
  95.                   Set_clip(Scalex(p[0]),Scaley(p[1]),
  96.                            Scalex(p[0])+Scalex(p[2]),
  97.                            Scaley(p[1])+Scaley(p[3]));
  98.                break;
  99.        case 7:        /* ras_copy specify dst,src */
  100.                if (p[6]>MAXBITMAPS || p[7]>MAXBITMAPS)
  101.                   break;
  102.                if (p[6]>0 && W(bitmaps)[p[6]-1]== (BITMAP *) 0) {
  103.                   W(bitmaps)[p[6]-1] = bit_alloc(
  104.                               Scalex(p[0])+Scalex(p[2]),
  105.                               Scaley(p[1])+Scaley(p[3]),NULL_DATA,DEPTH);
  106.                   }
  107. #ifdef DEBUG
  108.                dprintf(B)(stderr,"blitting %d to %d\n",p[7],p[6]);
  109. #endif
  110.                bit_blit(p[6]?W(bitmaps)[p[6]-1]:window,
  111.                            Scalex(p[0]),Scaley(p[1]),
  112.                            Scalex(p[2]),Scaley(p[3]),op,
  113.                            p[7]?W(bitmaps)[p[7]-1]:window,
  114.                            Scalex(p[4]),Scaley(p[5]));
  115.                if (Do_clip() && p[6]==0)
  116.                   Set_clip(Scalex(p[0]),Scaley(p[1]),
  117.                            Scalex(p[0])+Scalex(p[2]),
  118.                            Scaley(p[1])+Scaley(p[3]));
  119.        }
  120.    }
  121.  
  122. /*****************************************************************************
  123.  *    down load a bit map  - parse escape sequence
  124.  */
  125.  
  126. int
  127. win_map(win,window)
  128. register WINDOW *win;
  129. register BITMAP  *window;
  130.    {
  131.    register int cnt = W(esc_cnt);
  132.    register int *p = W(esc);
  133.    register int op;
  134.  
  135.    if (W(flags)&W_REVERSE)
  136.       op = ROP_INVERT(W(op));
  137.    else
  138.       op = W(op);
  139.  
  140.    switch(cnt) {
  141.       case 2:        /* bitmap to graphics point */
  142.          bit_blit(window,Scalex(W(gx)),Scaley(W(gy)),
  143.                          p[0],p[1],op,W(bitmap),0,0);
  144.          bit_destroy(W(bitmap));
  145.          if (Do_clip()) {
  146.             Set_clip(Scalex(W(gx)),Scaley(W(gy)),
  147.                      Scalex(W(gx))+p[0],Scaley(W(gy))+p[1]);
  148.             }
  149.          break;
  150.       case 3:        /* bitmap to graphics point  specify dest*/
  151.          if (p[2] > MAXBITMAPS)
  152.             break;
  153.          if (p[2]>0 && W(bitmaps)[p[2]-1]== (BITMAP *) 0)
  154.             W(bitmaps)[p[2]-1]=W(bitmap);
  155.          else {
  156.             bit_blit(p[2]?W(bitmaps)[p[2]-1]:window,
  157.                          Scalex(W(gx)),Scaley(W(gy)),
  158.                          p[0],p[1],op,W(bitmap),0,0);
  159.             bit_destroy(W(bitmap));
  160.             }
  161.          break;
  162.       case 4:        /* bitmap to specified point */
  163.          bit_blit(window,p[2],p[3],p[0],p[1],op,W(bitmap),0,0);
  164.          bit_destroy(W(bitmap));
  165.          if (Do_clip()) {
  166.             Set_clip(p[2],p[3],p[2]+p[0],p[3]+p[1]);
  167.             }
  168.          break;
  169.       case 5:        /* bitmap to specified point  specify dest */
  170.          if (p[4] > MAXBITMAPS)
  171.             break;
  172.          if (p[4]>0 && W(bitmaps)[p[4]-1]== (BITMAP *) 0)
  173.             W(bitmaps)[p[4]-1]=W(bitmap);
  174.          else {
  175.             bit_blit(p[4]?W(bitmaps)[p[4]-1]:window,
  176.                         p[2],p[3],p[0],p[1],op,W(bitmap),0,0);
  177.             bit_destroy(W(bitmap));
  178.             }
  179.          break;
  180.       }
  181.    W(snarf) = (char *) 0;
  182.    }
  183.  
  184. /*****************************************************************************
  185.  *    plot a line 
  186.  */
  187.  
  188. int
  189. win_plot(win,window)
  190. register WINDOW *win;
  191. BITMAP *window;
  192.     {
  193.     register int *p = W(esc);
  194.     int op;
  195.  
  196.     if (W(flags)&W_REVERSE)
  197.        op = ROP_INVERT(W(op));
  198.     else
  199.        op = W(op);
  200.  
  201.     switch (W(esc_cnt)) {
  202.        case 0:            /* set cursor to graphics point */
  203.                W(x) = Scalex(W(gx));
  204.                W(y) = Scaley(W(gy));
  205.                break;
  206.        case 1:            /* draw to graphics point */
  207.                Bit_line(win,window,Scalex(W(gx)),Scaley(W(gy)),
  208.                                Scalex(p[0]),Scaley(p[1]),op);
  209.                W(gx) = p[0];
  210.                W(gy) = p[1];
  211.                break;
  212.        case 3:
  213.                Bit_line(win,window,Scalex(p[0]),Scaley(p[1]),
  214.                                Scalex(p[2]),Scaley(p[3]),op);
  215.                     W(gx) = p[2];
  216.                     W(gy) = p[3];
  217.  
  218.                break;
  219.        case 4:
  220.                if (p[4]<MAXBITMAPS && W(bitmaps)[p[4]-1])
  221.                   bit_line(W(bitmaps)[p[4]-1],Scalex(p[0]),Scaley(p[1]),
  222.                                Scalex(p[2]),Scaley(p[3]),op);
  223.                break;
  224.        }
  225.     }
  226.  
  227. Bit_line(win,dst,x1,y1,x2,y2,op)
  228. register WINDOW *win;
  229. register BITMAP *dst;
  230. register int x1,y1,x2,y2,op;
  231.    {
  232. #ifdef DEBUG
  233.    dprintf(l)(stderr,"%s: line [%d] %d,%d %d,%d\n",W(tty),op,x1,y1,x2,y2);
  234. #endif
  235.    bit_line(dst,x1,y1,x2,y2,op);
  236.    if (Do_clip()) {
  237.       Set_clip(x1,y1,x2+1,y2+1); 
  238.       Set_clip(x2,y2,x1+1,y1+1); 
  239.       }
  240.    }
  241.  
  242.  
  243. /* experimantal graphics crunch mode */
  244.  
  245. int
  246. grunch(win,dst)
  247. WINDOW *win;    /* window */
  248. BITMAP *dst;    /* destination */
  249.     {
  250.    register char *buf = W(snarf);
  251.    register int cnt = W(esc)[W(esc_cnt)];
  252.    int op;
  253.     int penup = 0;
  254.    int *p = W(esc);
  255.     register int x,y,x1,y1;
  256.  
  257.    if (W(flags)&W_REVERSE)
  258.       op = ROP_INVERT(W(op));
  259.    else
  260.       op = W(op);
  261.  
  262.     /* set starting point */
  263.  
  264.     if (W(esc_cnt) > 1) {
  265.       x =  p[0];
  266.       y =  p[1];
  267.       }
  268.     else {
  269.       x = W(gx);
  270.       y = W(gy);
  271.         }
  272.     while (cnt-- > 0) {
  273.         x1 = (*buf>>4 & 0xf) - 8;
  274.         y1 = (*buf & 0xf) - 8;
  275.         if (x1==0 && y1 ==0)
  276.          penup = 1;
  277.       else if (penup == 0){
  278.          bit_line(dst,Scalex(x),Scaley(y),Scalex(x+x1),Scaley(y+y1),op);
  279. #ifdef DEBUG
  280.          dprintf(y)(stderr,"%s: line [%d] %d,%d + %d,%d\n",W(tty),op,x,y,x1,y1);
  281. #endif
  282.             x += x1;
  283.          y += y1;
  284.             }
  285.         else {
  286.             x += x1;
  287.          y += y1;
  288.             penup = 0;
  289.             }
  290.         buf++;
  291.         }
  292.     W(gx) = x;
  293.    W(gy) = y;
  294.     }
  295.  
  296. /*****************************************************************************
  297.  *    plot a circle 
  298.  */
  299.  
  300. int
  301. circle_plot(win,window)
  302. register WINDOW *win;
  303. BITMAP *window;
  304.     {
  305.     register int *p = W(esc);
  306.     int op;
  307.  
  308.     if (W(flags)&W_REVERSE)
  309.        op = ROP_INVERT(W(op));
  310.     else
  311.        op = W(op);
  312.  
  313.  
  314.     switch (W(esc_cnt)) {
  315.        case 0:        /* draw a 'circle'  at graphics point*/
  316.                circle(window,Scalex(W(gx)),Scaley(W(gy)),Scalexy(p[0]),op);
  317.                break;
  318.        case 1:        /* draw an 'ellipse' at graphics point */
  319.                ellipse(window, Scalex(W(gx)), Scaley(W(gy)),
  320.                                Scalex(p[0]), Scaley(p[1]), op);
  321.                break;
  322.        case 2:        /* draw a 'circle' */
  323.                circle(window,Scalex(p[0]),Scaley(p[1]),Scalexy(p[2]),op);
  324.                break;
  325.        case 3:        /* draw an 'ellipse' */
  326.                ellipse(window, Scalex(p[0]), Scaley(p[1]),
  327.                                Scalex(p[2]), Scaley(p[3]), op);
  328.                break;
  329.        case 4:        /* draw an 'ellipse' to offscreen bitmap */
  330.                if (p[4]<MAXBITMAPS && W(bitmaps)[p[4]-1])
  331.                   ellipse(W(bitmaps)[p[4]-1], Scalex(p[0]), Scaley(p[1]),
  332.                                Scalex(p[2]), Scaley(p[3]), op);
  333.                break;
  334.        case 5:        /* draw an arc  ccw centered at p0,p1 */
  335.                arc(window, Scalex(p[0]), Scaley(p[1]), Scalex(p[2]), Scaley(p[3]),
  336.                                Scalex(p[4]), Scaley(p[5]), op);
  337.                break;
  338.        case 6:        /* draw an arc  ccw centered at p0,p1  to offscreen bitmap */
  339.                if (p[6]<MAXBITMAPS && W(bitmaps)[p[6]-1])
  340.                   arc(W(bitmaps)[p[6]-1], Scalex(p[0]), Scaley(p[1]), Scalex(p[2]),
  341.                                 Scaley(p[3]), Scalex(p[4]), Scaley(p[5]), op);
  342.                break;
  343.        }
  344.     if (Do_clip())
  345.        Set_all();
  346.     }
  347.  
  348. /*****************************************************************************
  349.  *    move the graphics pointer
  350.  */
  351.  
  352. int
  353. win_go(win)
  354. register WINDOW *win;
  355.     {
  356.     register int *p = W(esc);
  357.  
  358.     switch (W(esc_cnt)) {
  359.        case 0:            /* set the graphics point to cursor pos */
  360.                W(gx) = W(x);
  361.                W(gy) = W(y);
  362.                break;
  363.        case 1: case 2:        /* set the graphics point */
  364.                W(gx) =  p[0];
  365.                W(gy) =  p[1];
  366.                break;
  367.        }
  368.     }
  369.